package com.tanhua.server.controller;

import com.tanhua.domain.vo.CommentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/comments")
@RestController
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping
    public ResponseEntity fingPage(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pagesize
            , String movementId) {
        PageResult<CommentVo> PageResult = commentService.findPage(page, pagesize, movementId);
        return ResponseEntity.ok(PageResult);
    }

    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map<String, String> param) {
        commentService.saveComment(param);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/{commentId}/like")
    public ResponseEntity like(@PathVariable String commentId){
       Integer likeCount= commentService.like(commentId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping(":/{commentId}/dislike")
    public ResponseEntity dislike(@PathVariable String commentId){
        Integer likeCount= commentService.dislike(commentId);
        return ResponseEntity.ok(likeCount);
    }
}
